package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// MallServiceQA 商场服务常见问题
type MallServiceQA struct {
	ID        string `json:"id" gorm:"column:id;primaryKey;type:int;size:64;comment:主键"`
	ServiceID string `json:"service_id" gorm:"column:service_id;type:int;size:64;index:idx_service"`
	Question  string `json:"question" gorm:"column:question;type:string;size:200"`
	Answer    string `json:"answer" gorm:"column:answer;type:text"`
	CreatedAt int64  `json:"created_at" gorm:"autoCreateTime;column:created_at;type:int;size:64;comment:创建时间"`
	UpdatedAt int64  `json:"updated_at" gorm:"autoUpdateTime;column:updated_at;type:int;size:64;comment:更新时间"`
}

func (MallServiceQA) TableName() string {
	return "mall_service_qa"
}

// BeforeCreate 自增id
func (m *MallServiceQA) BeforeCreate(tx *gorm.DB) (err error) {
	if m.ID != "" {
		return nil
	}
	// 用户id为空时，自动添加用户id
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	m.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &MallServiceQA{})
}
